/**
 * Created by HiWin10 on 2016/8/4.
 */
(function() {
    'use strict';

  var m= angular
        .module('app.deptlist', ['getdatamodule','chart.js']);
    m.controller('DeptListController',DeptListController);
    m.config(['ChartJsProvider', function (ChartJsProvider) {
        // Configure all charts

        ChartJsProvider.setOptions({

            colors : [ '#803690', '#00ADF9', '#DCDCDC', '#46BFBD', '#FDB45C', '#949FB1', '#4D5360'] ,

            title: {
                display: true,
                text: '学院报道情况',
                fullWidth:true,
                fontSize:24,
                fontColor:"#666",
                fontStyle:'bold'

            },
            legend: {
                display: true,
                labels: {
                    fontColor: 'rgb(255, 99, 132)'
                }
            }

        });
    }])
    DeptListController.$inject=['$scope','getdataservice','$timeout'];
    function DeptListController($scope,getdataservice,$timeout) {
        $scope.getexcel=baseurl+"/Excel/GetDeptExcel";
        $scope.isLoading=false;
        $scope.getdept=function () {
            $scope.isLoading=true
            $scope.havenums=0;
            $scope.regnums=0;

            var label=[];
            var data1=[];
            var data2=[];

            getdataservice.all('/department/index/v='+new Date().getTime()).then(function (data) {
                var label=[];
                var data1=[];
                var data2=[];
                $scope.collections=data.Data;

                angular.forEach(data.Data,function (dataa) {
                label.push(dataa.Dept_name);
                data1.push(dataa.Dept_havenum);
                data2.push(dataa.Dept_regnum);
                    $scope.havenums+=dataa.Dept_havenum;
                    $scope.regnums+=dataa.Dept_regnum;
                });

                $scope.labels = label;
                $scope.type = 'StackedBar';
                $scope.series = ['实报', '应报'];
                $scope.data = [
                  data1,
                    data2
                ];
                $scope.colors= ['#ff6384', '#00ADF9'];

                $scope.isLoading=false;
            },function () {
                $scope.isLoading=false;
            });
        };
        setInterval(function(){
            $scope.getdept();
        },30000);

    }
})();

